<template>
<div>
    <a-card :bordered="false" title="任务基础信息">
        <template #extra>
            <a-button key="back" icon="logout" class="ant-btn-warning" @click="close">返回</a-button>
            <template v-show="detail.status === 600">
                <a-button v-action:taskExtendTimeBtn type="primary" @click="initTaskState">延长执行时间</a-button>
            </template>
            <template v-show="detail.status === 300">
                <a-button v-action:taskImportOnlineBtn type="primary" icon="usergroup-add" @click="$refs.createTaskonlineAdd.add(detail)">导入接包人员名单</a-button>
            </template>
        </template>
        <detail-list :col="3">
            <detail-list-item term="任务名称">{{fieldForm.fieldTaskName}}</detail-list-item>
            <detail-list-item term="发布时间">{{detail.publishTime}}</detail-list-item>
            <detail-list-item term="园区公司">{{detail.parkName}}</detail-list-item>
            <detail-list-item term="任务价格">{{fieldForm.fieldTaskPrice}}</detail-list-item>
            <template v-if="detail.type === 1">
                <detail-list-item term="执行日期">{{fieldForm.fieldTaskStartDate}} - {{fieldForm.fieldTaskEndDate}}</detail-list-item>
            </template>
            <template v-if="detail.type === 2">
                <detail-list-item term="执行日期">{{fieldForm.fieldTaskStartDate}}</detail-list-item>
            </template>
            <detail-list-item term="任务类别">{{fieldForm.fieldTaskType}}</detail-list-item>
            <detail-list-item term="任务区域">{{cityLabel}}</detail-list-item>
            <detail-list-item term="需要人数">{{fieldForm.fieldTaskPeopleNumber}}</detail-list-item>
            <detail-list-item term="任务状态"><span>{{statusName}}</span></detail-list-item>
            <detail-list-item term="任务编号">{{detail.taskId}}</detail-list-item>
            <detail-list-item term="任务类型">{{detail.type === 1 ? '线上':'线下'}}</detail-list-item>
        </detail-list>
        <detail-list :col="1">
            <detail-list-item term="需求描述">{{fieldForm.fieldTaskDescription | filterMore(40)}}
                <a-button v-if="fieldForm.fieldTaskDescription.length>40" icon="eye" type="link" @click="openMore('需求描述',fieldForm.fieldTaskDescription);"></a-button>
            </detail-list-item>
            <detail-list-item term="报名要求">{{fieldForm.fieldTaskEnroll | filterMore(40)}}
                 <a-button v-if="fieldForm.fieldTaskEnroll.length>40" icon="eye" type="link" @click="openMore('报名要求',fieldForm.fieldTaskEnroll);"></a-button>
            </detail-list-item>
            <detail-list-item term="交付要求">{{fieldForm.fieldTaskDeliver | filterMore(40)}}
                <a-button v-if="fieldForm.fieldTaskDeliver.length>40" icon="eye" type="link" @click="openMore('交付要求',fieldForm.fieldTaskDeliver);"></a-button>
            </detail-list-item>
        </detail-list>
    </a-card>

    <template v-if="detail.type === 1">
    <a-card 
    v-if="detail.status === 300 || detail.status === 400"
    :bordered="false" 
    style="margin-top:20px"
    :tabList="taskUserTab"
    :activeTabKey="activeTabKey"
    @tabChange="callbackTab">
        <template #title>
            <label>任务接包人员</label>
            <template v-if="userInfo.type === 2">
                 <a-alert message="请勾选有效数据生成结算单！" style="display: inline-block;margin-left:20px" closable show-icon type="info" />
                 <a-alert v-if="onMsg" :message="onMsg" style="display: inline-block;margin-left:20px" closable show-icon type="error" />
            </template>
        </template>
        <template #tabBarExtraContent>
            <span v-show="activeTabKey ==='100' || activeTabKey ==='200'">

                <span v-show="billTotal >=1 && selectedRowKeys.length ===0">
                    <a-badge :offset="[-110,0]" :count="billTotal" :overflow-count="999" v-action:taskSettleListBtn>
                        <a-button type="primary" icon="search" @click="$refs.createTaskSttleBill.add(detail)">查看预结算单</a-button>
                    </a-badge>
                </span>
                <span v-show="billTotal >=1 && selectedRowKeys.length >=1">
                    <a-badge :offset="[-140,0]" :count="billTotal" :overflow-count="999" v-action:taskSettleListBtn>
                        <a-button type="primary" icon="search" @click="createSttleBill">生成/查看预结算单</a-button>
                    </a-badge>
                </span>
                <span v-show="billTotal === 0 && selectedRowKeys.length >=1">
                    <a-button type="primary" v-action:taskSettleListBtn icon="search" @click="createSttleBill">生成预结算单</a-button>
                </span>
            </span>
            <a-button type="primary" style="margin-left:10px" v-action:taskDJGBtn @click="queryDJG" icon="safety-certificate" :disabled="DJGBtnState">查询董监高</a-button>
            <span v-show="activeTabKey ==='100'">
                <a-button type="danger" style="margin-left:10px" v-action:taskSettleClearListBtn icon="delete" @click="batchDel">清空列表</a-button>
                <a-button type="primary" icon="solution" v-action:taskSignBtn @click="settleBchatSign" style="margin-left:10px" :disabled="signBtnState">去签约</a-button>
            </span>
            
            <!-- <a-button type="primary" style="margin-left:10px" @click="$refs.createTaskDeliver.add(true,1)" icon="solution" :disabled="deliverBtnState">批量上传交付物</a-button> -->
        </template>
        <form-create v-model="params.fApi" :rule="params.rule" :option="params.option" @btn-search-click="loadTable(true)" @btn-reset-click="reset"/>
        <a-alert v-if="tis" show-icon type="success">
            <span slot="message">
                {{tis}}<a style="margin-left:10px;" @click="clearKeys">清空</a>
            </span>
        </a-alert>
        <a-table 
        :columns="table.columns" 
        :pagination="table.pagination" 
        @change="handleTableChange"
        :rowSelection="selectionState ? rowSelection : undefined"
        rowKey="id"
        :rowClassName="rowClassName"
        :data-source="table.loadData" 
        :scroll="{ x: 2200 }">
            <span slot="action" slot-scope="text, record">
                <span v-show="activeTabKey ==='200' || activeTabKey ==='400'">
                    <span v-show="record.operateStatus === 1">
                         <a v-action:taskVerifyEnrollBtn @click="$refs.createTaskEnroll.add(record)">审核报名</a>
                         <a-divider v-action:taskVerifyEnrollBtn type="vertical" />
                    </span>
                    <span v-show="record.operateStatus >= 2">
                        <a v-action:taskQueryEnrollBtn class="color-grey" @click="$refs.createTaskEnroll.add(record)">查看报名</a>
                        <a-divider v-action:taskQueryEnrollBtn type="vertical" />
                    </span>
                    <span v-show="record.operateStatus === 5">
                        <a v-action:taskVerifyInteractionBtn @click="$refs.createTaskInteraction.add(record,2)">审核交付物</a>
                        <a-divider v-action:taskVerifyInteractionBtn type="vertical" />
                    </span>
                    <span v-show="record.operateStatus >= 6">
                        <a v-action:taskQueryInteractionBtn class="color-grey" @click="$refs.createTaskInteraction.add(record,2)">查看交付物</a>
                        <a-divider v-action:taskQueryInteractionBtn type="vertical" />
                    </span>
                    
                </span>
                <span v-show="activeTabKey ==='200' && record.signStatus === 4">
                    <a-popconfirm
                        :title="`${record.userName} `+'发起重新签约'"
                        ok-text="确认"
                        cancel-text="取消"
                        @confirm="againSign(record)" >
                        <a v-action:taskAgainSignBtn>重新签约</a>
                    </a-popconfirm>
                    
                </span>
                <span v-show="activeTabKey ==='100'">
                    <a-popconfirm
                        :title="'是否删除用户'+`${record.userName} `+'？删除后用户在小程序端关联的任务也会删除？'"
                        ok-text="删除"
                        cancel-text="取消"
                        @confirm="delUser(record)" >
                        <a v-action:taskSettleDelBtn>删除</a>
                    </a-popconfirm>
                </span>
            </span>
            <span slot="phone" slot-scope="text, record">
                 <a-popover title="手机号" trigger="hover">
                    <template #content>
                    <p style="margin: 0;">{{record.phone}}</p>
                    </template>
                    <a-button style="padding: 0;color:#000" type="link">{{record.phone | filterMore(8)}}</a-button>
                </a-popover>
            </span>
            <span slot="idCard" slot-scope="text, record">
                 <a-popover title="身份证号" trigger="hover">
                    <template #content>
                    <p style="margin: 0;">{{record.idCard}}</p>
                    </template>
                    <a-button style="padding: 0;color:#000" type="link">{{record.idCard | filterMore(8)}}</a-button>
                </a-popover>
            </span>
            <span slot="bankCard" slot-scope="text, record">
                 <a-popover title="银行卡号" trigger="hover">
                    <template #content>
                    <p style="margin: 0;">{{record.bankCard}}</p>
                    </template>
                    <a-button style="padding: 0;color:#000" type="link">{{record.bankCard | filterMore(8)}}</a-button>
                </a-popover>
            </span>
            <span slot="operateStatus" slot-scope="text, record">
                <a-tag color="blue" v-if="text===1">已报名</a-tag>
                <a-tag color="green" v-if="text===2">已中标</a-tag>
                <a-tag color="red" v-if="text===3">未中标</a-tag>
                <a-tag color="pink" v-if="text===4">已取消</a-tag>
                <a-tag color="orange" v-if="text===5">待验收</a-tag>
                <a-tag color="green" v-if="text===6">已完成</a-tag>
                <a-tag color="cyan" v-if="text===7">验收失败</a-tag>
                <a-tag color="purple" v-if="text===8">已过期</a-tag>
            </span>
      </a-table>
    </a-card>
    </template>
    <task-online ref="createTaskonlineAdd" @on-ok="getTaskDetails"/>
    <task-sttle-bill ref="createTaskSttleBill" @on-ok="getTaskDetails"/>
    <task-enroll ref="createTaskEnroll" @on-ok="getTaskDetails"/>
    <task-interaction ref="createTaskInteraction" @on-ok="getTaskDetails"/>
    <task-sign ref="createTaskSign" @on-ok="setSign"/>
    <task-deliver ref="createTaskDeliver" @on-ok="getTaskDetails"/>
</div>

</template>
<script>
import { mapGetters,mapActions} from 'vuex'
import store from '@/store'
import {
    CITY_DATA
} from '@/config/baseData'
import {
    checkChinese
} from '@/utils/util'
import 
  TaskSign
from './task_sign'
import 
  TaskOnline
from './task_online'
import 
  TaskSttleBill
from './task_sttle_bill'
import 
  TaskEnroll
from './task_enroll'

import 
  TaskInteraction
from './task_interaction'
import 
  TaskDeliver
from '@/views/application/modules/task_deliver'
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item
import {
    PARAMS_TASK_USER,
    COLUMNS_TASK_IMPORT_USER,
    COLUMNS_TASK_ENROLL,
    COLUMNS_TASK_STTLE,
    OPTION_BLOCK,
    OPTION_INLINE,
    TASK_CATEGORY_DATA,
    TASK_USER_TAB_ENTERPRISE,
    TASK_TAB_ENTERPRISE
} from './form'
import { 
    allOnlineTaskDetail
} from '@/api/manage/task'
import { allsettleEnrollSign } from '@/api/manage/sign'
import { 
    allQueryImportTaskSttleUserDetailedList,
    getSettlementCount,
    allGetTaskSttleBillIsOpenAccount,
    allQueryEnrollUserDetailedList,
    allQueryTaskEnrollUserDJG,
    allQueryImportTaskUserDJG,
    allQueryHistoricImportTaskSttleUserDetailedList,
    allQueryHistoricEnrollUserDetailedList,
    allCreateTaskSttleBill,
    allQueryTaskSttleDetailedBillList,
    allDelImportTaskSttleUser,
    batchDelUserInfo
} from '@/api/manage/sttle'
export default {
    name: 'taskDetails',
    components: {
        DetailList,
        DetailListItem,
        TaskOnline,
        TaskSttleBill,
        TaskEnroll,
        TaskInteraction,
        TaskSign,
        TaskDeliver
    },
    data () {
        return {
            cityLabel:'',
            statusName:'',
            activeTabKey:'100',
            fieldForm:{
                fieldTaskDeliver: "",
                fieldTaskDescription: "",
                fieldTaskEnroll: "",
                fieldTaskStartDate: "",
                fieldTaskEndDate: "",
                fieldTaskName: "",
                fieldTaskPark: "",
                fieldTaskPeopleNumber: "",
                fieldTaskPrice: "",
                fieldTaskRegion: "",
                fieldTaskType: ""
            },
            detail:{},
            params:{
                fApi:{},
                rule:PARAMS_TASK_USER,
                option:OPTION_INLINE
            },
            taskUserTab:TASK_USER_TAB_ENTERPRISE,
            table:{
                columns:[],
                loadData:[],
                pagination:{
                    current:1,
                    pageSize: 5,
                    total:0,
                    showSizeChanger: true,
					showQuickJumper: true,
                    pageSizeOptions: ["10", "20", "50", "500"],
                    showTotal: total => `共有 ${total} 条数据`,
                }
            },
            selectedRowKeys:[],
            tis:"",
            selectedRows:[],
            billTotal:0,
            onMsg:'',
            onState:'',
        }
    },
    filters: {
        filterMore (value,num) {
            if (!value) return ''
            if (value.length > num) {
                return value.slice(0,num) + '...'
            }
            return value
        },
        
    },
    computed: {
        ...mapGetters(['userInfo','enterAccount','serviceFee']),
        selectionState(){
            var flag = false;
            if(this.userInfo.type === 2){
                if(this.activeTabKey === '100' || this.activeTabKey === '200'){
                    flag = true;
                }
            }
            return flag;
        },
        DJGBtnState(){
            var flag = true;
            if(this.table.loadData.length !==0 && this.activeTabKey === '200'){
                flag = false;
            }
            return flag;
        },
        signBtnState(){
            var flag = true;
            const checkboxKeys = this.selectedRowKeys;
            if(this.selectedRows.length !==0 && this.activeTabKey === '100' && checkboxKeys.length !==0){
                let total = 0;
                const newData = this.selectedRows.filter(v=>checkboxKeys.includes(v.id));
                newData.forEach(v=>{
                    if(v.signStatus === 2){
                        total =+ 1;
                    }
                })
                if(total > 0){
                    flag = true;
                }else{
                    flag = false;
                }
            }
            return flag;
        },
        rowSelection(){
            return {
                selectedRowKeys:this.selectedRowKeys,
                fixed:true,
                onChange:this.onSelectChange,
                onSelect:this.onSelectSingleChange,
                getCheckboxProps: this.getCheckboxProps
            }
        }
    },
    watch: {
        selectedRows:{ 
            handler(loadData){
                if(loadData.length === 0){
                    this.onMsg = '';
                    return;
                }
                if((this.activeTabKey === '100' || this.activeTabKey === '200') && this.serviceFee.signOrdering === 1){
                    let total = 0;
                    let texts = '';
                    loadData.map(v=>{
                        if(v.signStatus === 2){
                            total++;
                        }
                    })
                    if(total === loadData.length){
                       this.onMsg = '';
                    }else{
                        this.onMsg = '有未签约人员，请立刻签约';
                    }
                }
            },
            deep:true,
            immediate:true
        },
    },
    created () {
        this.generateRoutes();
        this.initData();
        this.getTaskDetails();
    },
    methods:{
         ...mapActions({
        generateRoutes:'generateRoutes'
        }),
        initData(){
            if(this.activeTabKey === '100'){
                let taskUserKey = this.userInfo.roleFiledAuthorities.taskUserKey;
                if(taskUserKey && taskUserKey.length >= 1){
                    this.table.columns = COLUMNS_TASK_IMPORT_USER.filter(v=> !taskUserKey.includes(v.dataIndex));
                }else{
                    this.table.columns = COLUMNS_TASK_IMPORT_USER;
                }
               
            }else if(this.activeTabKey === '200'){
                let taskEnrollKey = this.userInfo.roleFiledAuthorities.taskEnrollKey;
                if(taskEnrollKey && taskEnrollKey.length >= 1){
                    this.table.columns = COLUMNS_TASK_ENROLL.filter(v=> !taskEnrollKey.includes(v.dataIndex));
                }else{
                    this.table.columns = COLUMNS_TASK_ENROLL;
                }
            }else{
                let taskSttleKey = this.userInfo.roleFiledAuthorities.taskSttleKey;
                if(taskSttleKey && taskSttleKey.length >= 1){
                    this.table.columns = COLUMNS_TASK_STTLE.filter(v=> !taskSttleKey.includes(v.dataIndex));
                }else{
                    this.table.columns = COLUMNS_TASK_STTLE;
                }
            } 
        },
        onSelectSingleChange(record, selected, selectedRows){
            if(!selected){
                this.selectedRows.splice(this.selectedRows.findIndex(item=>item.id===record.id),1);
            }
        },
        onSelectChange(selectedRowKeys, rows) {
            this.selectedRowKeys = selectedRowKeys;
            const arrayObject = this.selectedRows.concat(rows);
            for(let obj of arrayObject){
                let rowsIdx = this.selectedRows.map(v=>v.id);
                if(!rowsIdx.includes(obj.id)){
                    this.selectedRows.push(obj);
                }
            }
            this.tis="已选择 "+selectedRowKeys.length+" 项";
            if(selectedRowKeys.length==0){
               this.clearKeys();
            }
        },
        clearKeys(){
            this.tis="";
            this.selectedRowKeys = [];
            this.selectedRows = [];  
        },
        getCheckboxProps(record) {
            return ({
                props: {
                    disabled: this.signState(record)
                },
            });
        },
        batchDel(){
            let that = this;
            let type = this.activeTabKey == '100' ? 1:2;
            let types = this.activeTabKey == '100' ? '导入人员明细':'报名人员明细';
            let text = '是否清空' +types+'，清空后不能恢复？'
            this.$confirm({
                title: text,
                async onOk() {
                    let params = {type:type,taskId:that.$route.query.taskId}
                    const {code} = await batchDelUserInfo(params);
                    if(code === '1'){
                        that.$message.success('操作成功');
                        that.getTaskDetails();
                    }
                },
                onCancel() {},
            });
        },
        signState(item){
            var flag = true;
            if(this.activeTabKey === '100'){
                flag = false;
            }else if(this.activeTabKey === '200' && item.signStatus === 2 && item.realNameStatus === 2){
                flag = false;
            }
            return flag;
        },
        async getTaskDetails(){
            const {code,data} = await allOnlineTaskDetail(this.$route.query.id);
            if(code === '1'){
                Object.assign(this.detail,data);
                for(var key in data.dynamicFields){
                    if(data.dynamicFields.hasOwnProperty(key) && this.fieldForm.hasOwnProperty(key)){
                        this.fieldForm[key] = data.dynamicFields[key];
                        if(key === 'fieldTaskType' && !checkChinese(data.dynamicFields[key])){
                            this.fieldForm[key] = TASK_CATEGORY_DATA.find(v=>v.value.includes(data.dynamicFields[key])).label;
                        }
                    }
                }
                TASK_TAB_ENTERPRISE.forEach(v=>{
                    if(v.key == this.detail.status){
                        this.statusName = v.tab;
                    }
                })

                if(data.type === 1){
                    CITY_DATA.forEach(v => {
                        if(v.value == this.fieldForm.fieldTaskRegion){
                            this.cityLabel = v.label;
                        }
                    });
                }else if(data.type === 2){
                    this.cityLabel = this.fieldForm.fieldTaskRegion
                }
                
                if(data.status === 300 || data.status === 400){
                    this.loadTable();
                }

                if(data.status === 300 && this.userInfo.type ===2){
                    this.getEnterParkOpenState();
                }
            }
        },
        initTaskState(){
            this.$message.error('功能升级中！');
        },
        callbackTab(keys){
            this.activeTabKey = keys;
            this.table.pagination.current =1;
            this.table.pagination.pageSize = 5;
            this.initData();
            this.clearKeys();
            this.loadTable(true);
        },
        async loadTable(flag){
            let params = {};
            if(JSON.stringify(this.params.fApi) !== "{}"){
                const formData = this.params.fApi.formData();
                params.userName = formData.userName;
                params.idCard = formData.idCard;
                params.phone = formData.phone;
                params.realNameStatus = formData.realNameStatus;
                params.signMode = formData.signMode;
                params.signStatus = formData.signStatus;
                params.startTime = formData.day[0];
                params.endTime = formData.day[1];
            }
            if(flag){
                this.table.pagination.current = 1;
                this.table.pagination.pageSize = 5;
                this.clearKeys();
            }
            params.taskId = this.$route.query.taskId;
            params.pageNum = this.table.pagination.current;
            params.pageSize = this.table.pagination.pageSize;
            this.table.loadData = [];
            if(this.activeTabKey === '100'){
                const {code,data} = await allQueryImportTaskSttleUserDetailedList(params);
                if(code ==='1'){
                    this.table.loadData = data.content;
                    this.table.pagination.total = data.total || 0;
                }
            }else if(this.activeTabKey === '200'){
                const {code,data} = await allQueryEnrollUserDetailedList(params);
                if(code ==='1'){
                    this.table.loadData = data.content;
                    this.table.pagination.total = data.total || 0;
                }
            }else if(this.activeTabKey === '300'){
                 const {code,data} = await allQueryHistoricImportTaskSttleUserDetailedList(params);
                 if(code ==='1'){
                    this.table.loadData = data.content;
                    this.table.pagination.total = data.total || 0;
                }
            }else if(this.activeTabKey === '400'){
                 const {code,data} = await allQueryHistoricEnrollUserDetailedList(params);
                 if(code ==='1'){
                    this.table.loadData = data.content;
                    this.table.pagination.total = data.total || 0;
                }
            }
        },
        rowClassName(record, index) {
            if(this.activeTabKey === '100' && record.signStatus !== 2){
                return "bg-red"
            }else if(this.activeTabKey === '200' && record.signStatus !==2){
                return "bg-red"
            }
            return "";
        },
        handleTableChange(pagination){
            this.table.pagination.current = pagination.current;
            this.table.pagination.pageSize = pagination.pageSize;
            this.loadTable(false);
        },
        reset(){
            this.params.fApi.resetFields();
            this.loadTable(true);
        },
        close(){
            this.$router.push({name:this.$route.query.flag});
        },
        async delUser(item){
            let params = {id:item.id};
            const {code} = await allDelImportTaskSttleUser(params);
            if(code === '1'){
                this.$message.success('操作成功');
                this.selectedRowKeys.splice(this.selectedRowKeys.findIndex(ids=>ids===item.id),1);
                this.selectedRows.splice(this.selectedRows.findIndex(v=>v.id===item.id),1);
                this.tis="已选择 "+this.selectedRowKeys.length+" 项";
                if(this.selectedRowKeys.length === 0){
                    this.tis = '';
                }
                this.getTaskDetails();
            }
        },
        async getEnterParkOpenState(){
            const that = this;
            const parkId = this.detail.parkId;
            const enterpriseId = this.detail.enterpriseId;
            const {code,data} = await allGetTaskSttleBillIsOpenAccount(parkId,enterpriseId);
            if(code === '1'){
                if(data && data.length > 0){
                    let arr = [];
                    data.forEach(v=>{
                        if(v.type === 1){
                            let payState = {};
                            payState.payChannel = v.payChannel;
                            payState.accountStatus = v.accountStatus;
                            arr.push(payState)
                        }
                    })
                    if(arr.length === 0){
                        that.onMsg = '生成结算单需要先开户，请联系运营人员立即开户！';
                        that.onState = 2;
                    }
                    this.initQuerySttleBill();
                }else{
                    that.onMsg = '生成结算单需要先开户，请联系运营人员立即开户！';
                    that.onState = 2;
                }
            }
        },
        async initQuerySttleBill(){
            let params = {taskId:this.$route.query.taskId}
            const {code,data} = await getSettlementCount(params);
            if(code ==='1'){
                this.billTotal = data;
            }
        },
        async createSttleBill(){
            const that = this;
            if(this.onState === 2){
                return this.$message.error('生成结算单需要先开户，请联系运营人员立即开户！');
            }
            const selectedRowKeys = [];
            this.selectedRows.forEach(v=>{
                if(this.selectedRowKeys.indexOf(v.id) != -1){
                    selectedRowKeys.push(v);
                }
            })

            for(var i=0;i<selectedRowKeys.length;i++){

                if(this.activeTabKey === '100' && selectedRowKeys[i].signStatus !== 2 && this.serviceFee.signOrdering === 1){
                    let tips = selectedRowKeys[i].userName +'未签约，不能结算，请立即签约!';
                    return this.$message.error(tips)
                }else if(this.activeTabKey === '200' && selectedRowKeys[i].signStatus !== 2){
                    let tips = selectedRowKeys[i].userName +'未签约，不能结算，请立即签约!';
                    return this.$message.error(tips)
                }
            }

            let praams = {ids:this.selectedRowKeys};
            const {code} = await allCreateTaskSttleBill(praams);
            if(code === '1'){
                this.getTaskDetails();
                this.clearKeys();
                that.$confirm({
                    content: '生成预结算单成功',
                    cancelText:'关闭',
                    okText:'查看',
                    onOk() {
                        that.$refs.createTaskSttleBill.add(that.detail)
                    },
                    onCancel() { },
                })
            }
        },
        async againSign(rows){
            let params = {
                taskId:this.$route.query.taskId,
                idCard:rows.idCard,
                username:rows.userName,
                phone:rows.phone
            }
            const {code} = await allsettleEnrollSign(params);
            if(code === '1'){
                this.$message.success('操作成功');
                this.getTaskDetails();
            }
        },
        settleBchatSign(){
            if(this.selectedRowKeys.length === 0){
                return this.$message.error('请勾选签约对应人员！');
            }
            const selectedRowKeys = [];
            this.selectedRows.forEach(v=>{
                if(this.selectedRowKeys.indexOf(v.id) != -1){
                    selectedRowKeys.push(v);
                }
            })
            const sginSate = selectedRowKeys.map(v=>v.signStatus);
            if(sginSate.includes(2)){
                return this.$message.error('只能对未签约用户进行签约，请重新筛选用户');
            }
            this.$refs.createTaskSign.add(selectedRowKeys,this.detail);
        },
        setSign(){
            this.clearKeys();
            this.getTaskDetails();
        },
        async queryDJG(){
            let praams = {taskId:this.$route.query.taskId};
            const {code} = await allQueryTaskEnrollUserDJG(praams);
            if(code === '1'){
                this.getTaskDetails();
            }
        },
        openMore(files,val){
            this.$success({
                okText:'关闭',
                maskClosable:true,
                title: files,
                content: val,
            });
        }
    },
    beforeCreate() {},
}
</script>
